//
//  MyChangeNiChengLableViewController.m
//  VEMoneyPorject
//
//  Created by 陈建 on 2018/9/24.
//  Copyright © 2018年 陈建. All rights reserved.
//

#import "MyChangeNiChengLableViewController.h"
#import "MyInputNameTextFieldTableViewCell.h"
@interface MyChangeNiChengLableViewController ()
{
    NSString *_userName;
}
@end

@implementation MyChangeNiChengLableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isSuccessNet = YES;
    
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    [self cj_setUpNavRightItemTitle:@"保存" handle:^(NSString *rightItemTitle) {
        
        if (![CJUIKit isNilOrNull:self->_userName] && ![[CJUserInfoManager sharedManager].currentUserInfo.USERNAME isEqualToString:self->_userName]) {
            CJBaseRequest *request = [CJBaseRequest cj_requestWithUrl:[NSString stringWithFormat:@"%@/VEService/EditUsername.do",kPublicInterfaceAPI] isPost:YES withParameters:@{@"Userid":[[CJUserInfoManager sharedManager] currentUserInfo].USERID,@"Username":self->_userName}];
            [request cj_sendRequestWithCompletion:^(id response, BOOL success, NSString *message) {
                
                NSLog(@"%@",response);
                [CJUIKit showSuccessWithStatus:@"保存成功"];
                UserInfoModel *model = [CJUserInfoManager sharedManager].currentUserInfo;
                model.USERNAME = self->_userName;
                [[CJUserInfoManager sharedManager] resetUserInfoWithUserInfo:model];
                
            }];
        }
    }];
    
    // Do any additional setup after loading the view.
}



- (NSInteger)cj_numberOfSections{
    return 1;
}

- (NSInteger)cj_numberOfRowsInsection:(NSInteger)section{
    return 1;
}

- (CGFloat)cj_cellHeightAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

- (CJBaseTableViewCell *)cj_cellAtIndexPath:(NSIndexPath *)indexPath{
    MyInputNameTextFieldTableViewCell *cell = [MyInputNameTextFieldTableViewCell nibWithTableView:self.tableView];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.titleLable.textColor = [UIColor colorWithHexString:kNomalTextBlackColor];
    cell.titleLable.text = @"昵称";
    cell.detailTextField.placeholder = @"请输入昵称";
    cell.detailTextField.textColor = [UIColor colorWithHexString:kDetailTextBlackColor];
    cell.detailTextField.text = [CJUserInfoManager sharedManager].currentUserInfo.USERNAME;
    [cell.detailTextField addTarget:self action:@selector(detailTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    return cell;
}

- (void)detailTextFieldDidChange:(UITextField *)textField{
    _userName = textField.text;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
